# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=radicale
pkgver=3.3.0
pkgrel=0
pkgdesc="Free and open-source CalDAV and CardDAV server"
url="https://radicale.org/"
arch="noarch"
license="GPL-3.0-or-later"
depends="py3-passlib py3-vobject py3-defusedxml py3-dateutil py3-setuptools"
makedepends="py3-gpep517 py3-wheel"
checkdepends="py3-bcrypt py3-pytest py3-waitress"
pkgusers="radicale"
pkggroups="radicale"
install="$pkgname.pre-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/Kozea/radicale/archive/v$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	"
subpackages="$pkgname-openrc $pkgname-pyc"
builddir="$srcdir/Radicale-$pkgver"

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	python3 -m venv --clear --without-pip --system-site-packages .testenv
	gpep517 install-wheel --destdir .testenv --prefix '' .dist/*.whl
	.testenv/bin/python3 -m pytest -c /dev/null
}

package() {
	gpep517 install-wheel --destdir "$pkgdir" \
		.dist/*.whl

	install -d -o radicale -g radicale "$pkgdir"/var/lib/radicale \
		"$pkgdir"/var/log/radicale

	install -d "$pkgdir"/etc/radicale
	install -m640 -g radicale config "$pkgdir"/etc/radicale/
	install -m640 -g radicale rights "$pkgdir"/etc/radicale/

	install -Dm755 "$srcdir"/radicale.initd "$pkgdir"/etc/init.d/radicale
	install -Dm644 "$srcdir"/radicale.confd "$pkgdir"/etc/conf.d/radicale
}

sha512sums="
02d4f1a6d2e298b74d7076d90a0bc2dc60e6d4b29b37279de3a15f4c1db7c9996685400c4899399a39693abd02b383c4862a59d6720292517543600c7b25fc06  radicale-3.3.0.tar.gz
f1eb4477ca7d7d8040837b712289f18d6b62c7f862a8e9bea32968a49b8bf4394360b5440c815aa23df48ba0aaac61bcb8c9d6e7575c3b23da2ac05a45eac194  radicale.initd
09bb6228ba07039b97b317d4547a33b7ebf9c8f47ff72b870fc2f5e46de620e0614d993c5c96d73f0ad6196d469bb0f7206478781abf314af1d598e3132d678e  radicale.confd
"
